package com.ranshiyan.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ranshiyan.dao.StuMapper;
import com.ranshiyan.entity.Area;
import com.ranshiyan.entity.Student;
import com.ranshiyan.entity.Subject;
//b1
@Service
public class StuServiceImpl implements StuService{

	@Autowired
	StuMapper stuMapper;
	
	@Override
	public List<Student> listStudent() {
		// TODO Auto-generated method stub
		return stuMapper.listStudent();
	}

	@Override
	public List<Subject> listsubject() {
		// TODO Auto-generated method stub
		return stuMapper.listsubject();
	}

	@Override
	public List<Area> listArea(int id) {
		// TODO Auto-generated method stub
		return stuMapper.listArea(id);
	}

	@Override
	public int add(Student student,int[] subjectId) {
		// TODO Auto-generated method stub
		int addstudent = stuMapper.addstudent(student);
		for (int i : subjectId) {
			int addstusub = stuMapper.addstusub(student.getId(), i);
			System.out.println(student.getId()+"ssss");
		}
		return addstudent;
	}

	@Override
	public Student findStudent(int id) {
		// TODO Auto-generated method stub
		return  stuMapper.findStudent(id);
	}

	@Override
	public void update(Student student,int[] subjectId) {
		// TODO Auto-generated method stub
		stuMapper.updateStudent(student);

		stuMapper.deletestusub(student.getId());

		for (int i = 0; i < subjectId.length; i++) {
			stuMapper.addstusub(student.getId(), subjectId[i]);
		}
		
	}

}
